package com.autonavi.yunda.yunji.common.configuration;

import com.autonavi.yunda.yunji.common.thread.TraceableThreadPoolTaskExecutor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.ThreadPoolExecutor;

/**
 * 公用线程池配置
 *
 * @author liwenjie
 * @date 2023/09/07
 */
@Configuration
public class CommonExecutorConfiguration {

    @Bean
    public TraceableThreadPoolTaskExecutor lindormExecutor() {
        TraceableThreadPoolTaskExecutor lindormExecutor = new TraceableThreadPoolTaskExecutor();
        lindormExecutor.setCorePoolSize(8);
        lindormExecutor.setMaxPoolSize(50);
        lindormExecutor.setQueueCapacity(0);
        lindormExecutor.setKeepAliveSeconds(10000);
        lindormExecutor.setThreadNamePrefix("lindorm-worker-thread ");
        lindormExecutor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
        lindormExecutor.initialize();
        return lindormExecutor;
    }
}
